package reflectCus;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo4 {
    public static void main(String[] args) throws Exception {
        while (true){
            Scanner sc=new Scanner(System.in);
            System.out.println("清输入类名:");
            String claaname=sc.next();
            System.out.println("清输入方法名:");
            String method=sc.next();

            Class cls=Class.forName(claaname);
            Constructor c =  cls.getConstructor();
            Object o= c.newInstance();
            System.out.println(o);

//        Method m=cls.getMethod("play", String.class);
//        m.invoke(o,"泥巴!");
            Method m2=cls.getDeclaredMethod(method);
            m2.setAccessible(true);
            m2.invoke(o);

        }

    }
}
